package com.etc.team2.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.team2.service.LineService;

public class DeleteLineServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/*
		 * 获取lineId
		 *调用LineService中的deleteLine()方法， 删除指定lineId的线路
		 *删除完返回AllLineServlet
		 */
		String referer=request.getHeader("referer");
		if (referer==null||!referer.startsWith("http://localhost:")) {
			response.sendRedirect("home.jsp");
			return;
		}
		request.setCharacterEncoding("utf-8");
		int lineId=Integer.parseInt(request.getParameter("lineId"));
		if(new LineService().deleteLine(lineId)){
			response.sendRedirect("AllLineServlet");
		}else {
			System.out.println("删除失败");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);
	}

}
